package cn.hfatec.shms.web.yk.ykType.service;

import java.util.List;
import java.util.HashMap;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.web.yk.ykType.model.YkType;
import cn.hfatec.shms.web.yk.ykType.dao.YkTypeDao;
import cn.hfatec.shms.web.yk.ykType.model.YkTypeParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("YkTypeService")
public class YkTypeService {

    public static final String BEAN_ID = "YkTypeService";

    //注入Dao层
    @Resource(name = "YkTypeDao")
    private YkTypeDao ykTypeDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param ykTypeParams
     * @param page
     *
     */
    @Transactional
    public Table queryYkTypeTable(YkTypeParams ykTypeParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", ykTypeParams);
        return baseDao.queryTableByPage("queryYkType", params, page);
    }

    /**
     *
     * 插入数据
     * @param ykType
     *
     */
    @Transactional
    public void saveYkType(YkType ykType) {
        if(ykType.getId() != null) {
            YkType result = getYkType(ykType.getId());
            if(result != null) {
                ykTypeDao.update(ykType);
            } else {
                ykTypeDao.insert(ykType);
            }
        } else {
            ykTypeDao.insert(ykType);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteYkType(Integer id) {

        ykTypeDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param ykTypeList
     *
     */
    @Transactional
    public void deleteYkTypeBatch(List<String> ykTypeList) {
        for(String id : ykTypeList) {
            deleteYkType(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public YkType getYkType(Integer id) {

        return ykTypeDao.getYkTypeById(id);
    }

    /**
     *
     * 根据ID获取数据
     * @param productName
     *
     */
    @Transactional
    public YkType getYkTypeProductNam(String productName) {

        return ykTypeDao.getYkTypeByProductName(productName);
    }
}